<template>
    <div>
        <Form :label-width="100" ref="formInline" :model="formInline">
            <Row :gutter="16" class="query-form2">
                <i-col span="8">
                    <FormItem label="被检查单位：" prop="inspectionUnitName">
                        <Input v-model="formInline.inspectionUnitName" placeholder="请输入被检查单位"/>
                    </FormItem>
                </i-col>
                <i-col span="16">
                    <div style="float: right;">
                        <Button class="ivu-btn-query"  icon="md-search"  @click="query">查询</Button>
                        <Button class="ivu-btn-reset" style="margin-left: 10px" @click="cancel">重置</Button>
                    </div>
                </i-col>
            </Row>
        </Form>
        <Table ref='table' style="margin-top: 10px" :loading="loading" border :columns="columns" no-data-text="没有查询到相关数据！"
               :data="infos" width="100%" :height="tableHeight" highlight-row stripe size="small"></Table>
        <Row type="flex" justify="end" >
            <i-col>
                <Page :total="pagedata.total" :current="pagedata.currentPage" :page-size="pagedata.pageSize"
                      @on-page-size-change="pageSizeChange" @on-change="pageChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </i-col>
        </Row>
        <Modal :title="isUpdate? '监督检查隐患整改通知单修改': '监督检查隐患整改通知单新增'" :transfer=false v-model="modal1" :width=1000>
            <Form ref="formCustom" :model="formData" :rules="ruleCustom" label-position="top">
                <Row  :gutter="16">
                    <i-col span="24">
                        <FormItem label="被检查单位：" prop="inspectionUnitName">
                            <Input suffix="ios-search" placeholder="请选择被检查单位" v-model="formData.inspectionUnitName" readonly @on-focus="openOrgModal"/>
                        </FormItem>
                    </i-col>
                </Row>
                <Row :gutter="16">
                    <i-col span="12">
                        <FormItem label="检查部位：" prop="inspectionSite">
                            <Input v-model="formData.inspectionSite" placeholder="请输入被检查部位" type="text"/>
                        </FormItem>
                    </i-col>
                    <i-col span="12">
                        <FormItem label="检查日期：" prop="inspectionDate">
                            <DatePicker type="date" placeholder="请选择" style="width: 100%;"
                                        v-model="formData.inspectionDate"></DatePicker>
                        </FormItem>
                    </i-col>
                </Row>
                <Row :gutter="16" >
                    <i-col span="24">
                        <FormItem label="检查人员：" prop="inspectionUsers">
                            <Input v-model="formData.inspectionUsers" placeholder="请输入检查人员，用、符号进行分割" type="text"/>
                        </FormItem>
                    </i-col>
                </Row>
            </Form>
            <Row type="flex" justify="start" class="query-form" >
                <i-col>
                    <Button icon="md-add" class="ivu-btn-add" @click="addItemInfo">新增问题</Button>
                </i-col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg" :gutter="16">
                <i-col span="24" style="margin-top: 10px;margin-bottom: 10px">
                    <Table height="300" :loading="loading1" size="small" class="table" no-data-text="没有查询到相关数据!"
                           highlight-row stripe border :columns="columns3" width="100%" :data="apsgNoticeItem">
                    </Table>
                </i-col>
            </Row>
            <div slot="footer">
                <Button  @click="saveInfo" class="ivu-btn-save" :loading="buttonLoading">确定</Button>
                <Button @click="modal1 = false" class="ivu-btn-cancel" >取消</Button>
            </div>
        </Modal>
        <Modal title="公司列表" :transfer=false v-model="modal2" :width=1000 footer-hide>
            <Form :label-width="110" ref="formInline2" :model="formInline2">
                <Row :gutter="16" class="query-form2">
                    <i-col span="8">
                        <FormItem label="公司名称">
                            <Input v-model="formInline2.orgName" type="text"/>
                        </FormItem>
                    </i-col>
                    <i-col span="8">
                        <FormItem label="组织机构级别：">
                            <Select filterable v-model="formInline2.orgLevel"  @on-open-change="selectCodingSort"  >
                                <Option v-for="item in orgLevelList" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName }}</Option>
                            </Select>
                        </FormItem>
                    </i-col>
                    <i-col span="8">
                        <div style="float: right;">
                            <Button class="ivu-btn-query" icon="md-search" @click="queryOrg" style="margin-right: 10px">查询</Button>
                            <Button @click="resetOrg" class="ivu-btn-reset">重置</Button>
                        </div>
                    </i-col>
                </Row>
            </Form>
            <Table row-key='orgId' ref='table2' height="400" :loading="loading2" no-data-text="没有查询到相关数据!" border @on-select="selectionTable" @on-selection-change="changeTable"
                   :columns="orgColumn" :load-data="handleLoadData" width="100%" :data="orgDatas" size="small">
            </Table>
        </Modal>

        <Modal title="监督检查隐患整改通知单详情" :transfer=false v-model="modal3" :width=1000   @on-cancel="modal3=false" >
            <Row class="modal-view-detail">
                <i-col span="24">
                    <Form :model="formData" :label-width="160">
                        <Row :gutter="16" type="flex" justify="space-around" class="code-row-bg">
                            <i-col span="24">
                                <FormItem label="被检查单位：">
                                    {{formData.inspectionUnitName}}
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row :gutter="16" type="flex" justify="space-around" class="code-row-bg">
                            <i-col span="12">
                                <FormItem label="检查部位：">
                                    {{formData.inspectionSite}}
                                </FormItem>
                            </i-col>
                            <i-col span="12" >
                                <FormItem label="检查日期：">
                                    {{this.formatDate(new Date(this.formData.inspectionDate), 'yyyy-MM-dd')}}
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row :gutter="16" type="flex" justify="space-around" class="code-row-bg">
                            <i-col span="24">
                                <FormItem label="检查人员：">
                                    {{formData.inspectionUsers}}
                                </FormItem>
                            </i-col>
                        </Row>
                    </Form>
                    <Row type="flex" justify="space-around" :gutter="16" class="code-row-bg">
                        <i-col span="24" style="margin-top: 10px;margin-bottom: 10px">
                            <Table height="300" :loading="loading1" size="small"  no-data-text="没有查询到相关数据!"
                                   highlight-row stripe border :columns="columns3" width="100%" :data="apsgNoticeItem">
                            </Table>
                        </i-col>
                    </Row>
                </i-col>
            </Row>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="modal3 = false">关闭</Button>
            </div>
        </Modal>
        <Modal :transfer=false v-model="modal5"  :width=600 :title="'问题详情'"
               @on-cancel="modal5=false" >
            <Form class="modal-view-detail" :model="InputItemData" label-position="top" >
                <Row style="line-height: 42px;">
                    <i-col span='7'>
                        <span>检查发现问题：{{InputItemData.itemDesc}}</span>
                    </i-col>
                </Row>
                <Row class="detail-background-clor" style="line-height: 42px;">
                    <i-col span="23">
                        <FormItem label="照片：">
                            <div v-show="uploadList.length>0" v-for="item in uploadList" :key='item'  style="display: inline-block;margin-right: 10px">
                                <router-link target="_blank" :to="{path:'/imgDetails',query:{id:item.id}}">
                                    <img :src="item.picture" alt="" style="width: 50px;height: 50px;">
                                </router-link>
                                <br>
                                <a @click="downloadFile(form1datacopy.id,item)">{{ item.fileName }}</a>
                            </div>
                        </FormItem>
                    </i-col>
                </Row>
            </Form>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="model5=false">关闭</Button>
            </div>
        </Modal>

        <Modal v-model="modal7" width="900" :mask-closable="false">
            <Tabs>
                <TabPane label="历史记录">
                    <Table ref='table3' :loading="loading3" border :columns="historyColumns" style="margin-top: 0px"
                           :data="infos3" width="100%" :height="500" highlight-row stripe size="small"></Table>
                </TabPane>
                <TabPane label="流程图">
                    <div style="height: 500px; overflow-y: auto; overflow-x: auto">
                        <img :src="imgUrl" >
                    </div>
                </TabPane>
            </Tabs>
            <div slot="footer" >
                <Button @click="modal7=false" class="ivu-btn-save">关闭</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import {Api} from '../../../api'
    import {sessionStorage} from '@/common/cacheUtils.js';

    export default {
        name: "companyNotice",
        data(){
            return{
                view: false,
                fileUrl: Api.interestedPartiesUserFile,
                addItem: false,
                isUpdate: false,
                modal1: false,
                modal2: false,
                modal3: false,
                modal4: false,
                modal5: false,
                modal6: false,
                modal7: false,
                loading: false,
                loading3: false,
                buttonLoading: false,
                loading1: false,
                loading2: false,
                formInline: {},
                formInline2: {},
                formData: {},
                ruleCustom: {
                    inspectionUnitName: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ],
                    inspectionSite: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ],
                    inspectionDate: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change',
                            type: 'date'
                        }
                    ],
                    inspectionUsers: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ]
                },
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1
                },
                pageSizeArray: [10, 20, 50],
                columns: [
                    {
                        type: 'index',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    },
                    {
                        minWidth: 150,
                        title: '被检查单位',
                        align: 'center',
                        key: 'inspectionUnitName',
                    },
                    {
                        minWidth: 150,
                        title: '检查部位',
                        align: 'center',
                        key: 'inspectionSite',
                    },
                    {
                        minWidth: 150,
                        title: '检查日期',
                        align: 'center',
                        key: 'inspectionDate',
                        render: (h, params) => {
                            return h('div', [
                                (this.formatDate(new Date(params.row.inspectionDate), 'yyyy-MM-dd'))
                            ]);
                        }
                    },
                    {
                        minWidth: 150,
                        title: '检查人员',
                        align: 'center',
                        key: 'inspectionUsers',
                    },
                    {
                        title: '操作',
                        align: 'center',
                        key: 'view',
                        fixed: 'right',
                        minWidth: 170,
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px'
                                    },
                                    on: {
                                        click: () => {
                                            this.view = true;
                                            this.modal3 = true;
                                            this.updateRow(params.row);
                                        }
                                    }
                                }, '详情'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3"? '' : '#d0d0d0',
                                        pointerEvents: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? '' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.imgUrl = Api.getFlowImg + '/' + params.row.procinstId;
                                            this.queryHistory(params.row);
                                            this.modal7 = true;
                                        }
                                    }
                                }, '流程图'),
                            ]);
                        }
                    }
                ],
                infos: [],
                columns3: [
                    {
                        type: 'index',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    },
                    {
                        minWidth: 150,
                        title: '检查发现问题',
                        align: 'center',
                        key: 'itemDesc',
                    },
                    {
                        minWidth: 150,
                        title: '图片',
                        align: 'center',
                        render: (h, params) => {
                            let hfn = [];
                            if(params.row.files!=undefined){
                                params.row.files.forEach(v => {
                                    let url = this.fileUrl + '/file/' + v.id + '?field=problem';
                                    hfn.push(
                                        h('img', {
                                            style: {
                                                width: "30px",
                                                margin: "3px",
                                                cursor: "pointer"
                                            },
                                            attrs: {
                                                src: url
                                            }
                                        })
                                    )
                                });
                            }
                            return h('div', [...hfn]);
                        }
                    },
                    {
                        minWidth: 150,
                        title: '整改措施',
                        align: 'center',
                        key: 'itemMeasures',
                    },
                    {
                        minWidth: 150,
                        title: '整改图片',
                        align: 'center',
                        key: 'itemDesc',
                        render: (h, params) => {
                            let hfn = [];
                            if(params.row.files2 != undefined){
                                params.row.files2.forEach(v => {
                                    let url = this.fileUrl + '/file/' + v.id + '?field=measures'
                                    hfn.push(
                                        h('img', {
                                            style: {
                                                width: "30px",
                                                margin: "3px",
                                                cursor: "pointer"
                                            },
                                            attrs: {
                                                src: url
                                            }
                                        })
                                    )
                                });
                            }
                            return h('div', [...hfn]);
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                    },
                                    on: {
                                        click: () => {
                                            this.InputItemData = JSON.parse(JSON.stringify(params.row));
                                            this.getFiles(params.row.itemId);
                                            this.getFiles2(params.row.itemId);
                                            this.modal5 = true;
                                        }
                                    }
                                }, '详情'),
                            ]);
                        }
                    }
                ],
                apsgNoticeItem: [],
                orgColumn:[
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center',
                    },
                    {
                        title: '组织机构名称',
                        minWidth: 200,
                        align: 'left',
                        key: 'orgName',
                        tree:true
                    },
                    {
                        title: '组织机构级别',
                        width: 150,
                        align: 'center',
                        key: 'orgLevel',
                        render:(h, params) => {
                            return h('span', this.orgLevelMap[params.row.orgLevel]);
                        }
                    },
                ],
                orgDatas: [],
                tableHeight: '',
                userInfo: {},
                orgLevelMap:{},
                selectRow: {},
                orgLevelList: [],
                uploadList: [],
                InputItemData: [],
                reportData: {},
                ruleCustomReport: {
                    groupLeader: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ],
                    twoLevelGroupLeader: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ],
                    inspectionUnitName: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ],
                    companyLeader: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ],
                    CCUser: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur, change'
                        }
                    ]
                },
                ifCompany: false,
                leaderList: [],
                companyLeaderList: [],
                imgUrl: '',
                historyColumns: [
                    {
                        type: 'index',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    },
                    {
                        width: 180,
                        title: '审批时间',
                        key: 'endTime',
                        align: 'center',
                    },
                    {
                        width: 185,
                        title: '节点名称',
                        key: 'name',
                        align: 'center',
                    },
                    {
                        width: 120,
                        title: '审批人',
                        key: 'userName',
                        align: 'center'
                    },
                    {
                        width: 100,
                        title: '审批意见',
                        key: 'route',
                        align: 'center'
                    },
                    {
                        width: 200,
                        title: '备注',
                        key: 'opinions',
                        align: 'center'
                    },
                ],
                infos3: [],
                index: null
            }
        },
        watch: {
            'modal2': function(qw,er){
                if(!qw){
                    this.formInline2.orgName = '';
                    this.formInline2.orgLevel = '';
                }
            },
            'modal1': function (qw,er) {
                if(!qw){
                    this.formData = {};
                    this.apsgNoticeItem = [];
                }
            },
            'modal6': function (qw, er) {
                if(!qw){
                    this.companyLeaderList = [];
                    this.leaderList = [];
                    this.reportData = {};
                }
            }
        },
        mounted(){
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            this.userInfo = sessionStorage('userId').getObject('userId');
            this.selectCodingSort();
            this.query();
        },
        methods: {
            selectCodingSort(){
                this.$http.get(Api.queryCodeDetailBySortId +'/0200100005',{params:{}}).then((res) => {
                    this.orgLevelList = res.data.data;
                    this.orgLevelList.forEach(item=>{
                        this.orgLevelMap[item.codingCodeId] = item.codingName;
                    })
                })
            },
            addInfo(){
                this.view = false;
                this.modal1 = true;
                this.formData.createUserId = this.userInfo.userId;
                this.formData.createOrgId = this.userInfo.orgInfo.orgId;
                this.formData.id = this.uuid();
                this.isUpdate = false;
            },
            query(){
                this.loading = true;
                let data = {
                    startPage: this.pagedata.currentPage,
                    pageSize: this.pagedata.pageSize,
                    createUserId: this.userInfo.userId,
                };
                data = Object.assign(data,JSON.parse(JSON.stringify(this.formInline)));
                this.$http.get(Api.companyRectificationNotice + '//CC', {
                    params: data
                }).then(function(res){
                    this.infos = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    this.loading = false;
                }, function(res){
                    this.$Message.error('请求失败');
                });
            },
            pageSizeChange(pageSize){
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            pageChange(pageNum){
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            updateRow(row) {
                this.isUpdate = true;
                this.formData = row;
                this.loading1 = true;
                this.$set(this.formData, 'updateUserId', this.userInfo.userId);
                this.$set(this.formData, 'updateOrgId', this.userInfo.orgInfo.orgId);
                let apsgNoticeItem = row.apsgNoticeItems;
                apsgNoticeItem.forEach(v =>{
                    let url = this.fileUrl + '/' + v.itemId + '/files/picture'
                    this.$http.get(url, {params: {field : 'problem'}}).then((res) => {
                        if (res.data.result == "success") {
                            v.files = res.data.data
                        }
                    })
                });
                setTimeout(()=>{
                    this.apsgNoticeItem=apsgNoticeItem;
                    this.loading1=false
                },1000)
            },
            saveInfo(){
                this.$refs['formCustom'].validate((valid) => {
                    this.formData.apsgNoticeItems = this.apsgNoticeItem;
                    if(valid){
                        if(this.isUpdate) {
                            this.buttonLoading = true;
                            this.$http.put(Api.companyRectificationNotice, this.formData).then(function(response){
                                this.buttonLoading = false;
                                this.modal1 = false;
                                if(response.data.status == 200){
                                    this.$Message.success({ content: '保存成功', duration: 4 });
                                    this.query();
                                }else{
                                    this.$Message.error({ content: response.data.msg, duration: 4 });
                                }
                            });
                        }else{
                            this.buttonLoading = true;
                            this.$http.post(Api.companyRectificationNotice, this.formData).then(function(response){
                                this.buttonLoading = false;
                                this.modal1 = false;
                                if(response.data.status == 200){
                                    this.$Message.success({ content: '保存成功', duration: 4 });
                                    this.query();
                                }else{
                                    this.$Message.error({ content: response.data.msg, duration: 4 });
                                }
                            });
                        }
                    }
                });
            },
            deleteRow(row){
                this.$Modal.confirm({
                    title: '数据删除',
                    content: '<p>确定删除该条信息</p>',
                    okText: '确认',
                    onOk: () => {
                        this.$http.delete(Api.companyRectificationNotice, {params:{
                                id: row.id,
                                updateUserId: this.userInfo.userId,
                                updateOrgId: this.userInfo.orgInfo.orgId,
                            }}).then((res) => {
                            this.$Message.success({content:'删除成功',duration: 4});
                            this.query();
                        })
                    },
                    cancelText: '取消'
                });
            },
            reportRow(row){
                this.modal6 = true;
                this.reportData = { inspectionUnitName: row.inspectionUnitName, workId: row.id};
                this.userInfo.companyId == '18000000'? this.ifCompany= true: this.ifCompany = false;
                this.$http.get(Api.companyRectificationNotice+ '/user', { params: { companyId: this.userInfo.companyId, inspectionUnit: row.inspectionUnit, type: 1} }).then(function(res){
                    if(res.data.status == 200){
                        this.leaderList = res.data.data.leaderList;
                        this.companyLeaderList = res.data.data.companyLeaderList;
                    }
                }, function(res){
                    this.$Message.error('请求失败');
                });
            },
            openOrgModal(){
                this.modal2 = true;
                this.getOrgInfo();
            },
            getOrgInfo(){
                this.$http.get(Api.queryOrgDetailById + "/" + sessionStorage('userId').getObject('userId').companyId).then(res => {
                    this.orgDatas = [];
                    let temp = {};
                    temp._loading = false;
                    temp.children = [];
                    temp.orgName = res.data.data.orgName;
                    temp.orgId = res.data.data.orgId;
                    this.orgDatas.push(temp);
                }).catch(e => {
                    this.$Message.error('请求失败');
                })
            },
            handleLoadData (item, callback) {
                setTimeout(() => {
                    this.$http.get(Api.queryOrg, {
                        params: {
                            parentId: item.orgId,
                            codeAffordIf : 0
                        }
                    }).then(res => {
                        if(res.data.data.length !== 0) {
                            res.data.data.map(i => {
                                if(i.orgLevel != '0200100005000000007'){
                                    i._loading = false;
                                    i.children = [];
                                }
                            })
                            item.children = res.data.data;
                            callback(item.children);
                        } else {
                            delete item['_loading'];
                            item.children=[];
                            callback([]);
                        }
                    }).catch(e => {
                        this.$Message.error('请求失败');
                    })
                }, 2000);
            },
            uuid() {
                let s = [];
                let hexDigits = "0123456789abcdef";
                for(let i = 0; i < 32; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
                let uuid = s.join("");
                return uuid
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
            selectionTable(selection, row){
                // this.$refs.table2.selectAll(true);
                this.$set(this.formData, 'inspectionUnit', row.orgId);
                this.$set(this.formData, 'inspectionUnitName', row.orgName);
                this.modal2 = false;

                // this.selectRow = row;
            },
            queryOrg(){
                this.loading2 = true;
                this.$http.get(Api.queryOrgList+"?orgName="+this.formInline2.orgName+"&fromPage=1&pageSize=1000").then(res => {
                    let datas = [];
                    res.data.data.map(i => {
                        if(this.formInline2.orgLevel != ''&&i.orgLevel != this.formInline2.orgLevel){
                            return;
                        }
                        if(i.orgLevel != '0200100005000000007'){
                            i._loading = false;
                            i.children = [];
                        }
                        datas.push(i);
                    })
                    this.orgDatas = datas;
                    this.loading2 = false;
                }).catch(e => {
                    this.$Message.error('请求失败');
                    this.loading2 = false;
                })
            },
            resetOrg(){
                this.formInline2.orgName = '';
                this.formInline2.orgLevel = '';
                this.getOrgInfo();
            },
            addItemInfo(){
                this.addItem = true;
                this.uploadList = [];
                this.InputItemData = {
                    itemId:this.uuid(),
                    files:[],
                };
                this.modal4 = true
            },
            beforeUpload(file) {
                let index = file.name.lastIndexOf(".");
                let suffix = file.name.substr(index + 1);
                if (suffix != 'jpg' && suffix != 'jpeg' && suffix != 'png') {
                    this.$Message.error("请上传jpg,jpeg,png格式的图片");
                    this.file = null;
                    this.fileName = null;
                } else {
                    let formData = new FormData();
                    formData.append("files", file); // 文件对象
                    let url = this.fileUrl + '/' +this.InputItemData.itemId + '/files/picture/problem';
                    this.$http.post(url, formData).then((res) => {
                        if (res.data.result == "success") {
                            this.$Message.info("文件上传成功")
                            this.getFiles(this.InputItemData.itemId);
                            setTimeout(()=>{
                                this.InputItemData.files = this.uploadList
                            },300)
                        }
                    })
                }
                return false;
            },
            submitItem(name){
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        if (this.addItem){
                            this.apsgNoticeItem.push(this.InputItemData);
                            this.modal4 = false;
                        } else{
                            let index = this.index;
                            this.getFiles(this.InputItemData.itemId);
                            this.modal4 = false;
                            setTimeout(()=>{
                                this.apsgNoticeItem[index] = this.InputItemData;
                            },1000)
                        }
                    }else{
                        this.$Message.error('请填报完整!');
                    }
                })
            },
            submitReport(){
                this.$refs['reportForm'].validate((valid) => {
                    // if (valid) {
                        this.buttonLoading = true;
                        let data ={
                            // createUserId: this.userInfo.userId,
                            // user1: this.ifCompany? this.reportData.groupLeader: this.reportData.twoLevelGroupLeader,
                            // user2: this.reportData.companyLeader,
                            createUserId: '402819815aeec833015aeee5e9a4093f',
                            user1: '402819815aeec833015aeee5e9a4093f',
                            user2: '402819815aeec833015aeee5e9a4093f',
                            key: 'companyRectificationNotice',
                            workId: this.reportData.workId,
                            userName: this.userInfo.userName,
                            formKey: 'rectificationNoticeForm'
                        }
                        this.$http.post(Api.submit, data).then(function(response){
                            this.buttonLoading = false;
                            this.modal6 = false;
                            if(response.data.status == 200){
                                this.$Message.success({ content: '保存成功', duration: 4 });
                                this.query();
                            }else{
                                this.$Message.error({ content: response.data.msg, duration: 4 });
                            }
                        });
                    // }
                });
            },
            getFiles(id) {
                let url = this.fileUrl + '/' + id + '/files/picture';
                this.$http.get(url, {params: {field : 'problem'}}).then((res) => {
                    if (res.data.result == "success") {
                        this.uploadList  = res.data.data
                    }
                })
            },
            getFiles2(id) {
                let url = this.fileUrl + '/' + id + '/files/picture';
                this.$http.get(url, {params: {field : 'measures'}}).then((res) => {
                    if (res.data.result == "success") {
                        this.uploadList2  = res.data.data
                    }
                })
            },
            remove1(id,itemId) {
                let url = this.fileUrl + '/file/' + id;
                this.$http.delete(url).then((res) => {
                    this.getFiles(itemId)
                })
            },
            queryHistory(row){
                this.loading3 = true;
                this.$http.get(Api.getHistory + '/' + row.procinstId, {params: {}}).then((res) => {
                    this.infos3 = res.data;
                    this.loading3 = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            downloadFile(guideId, file) {
                let url = this.fileUrl + '/file/' + file.id;
                this.$http.get(url, {
                    responseType: 'blob'      //告诉服务器我们需要的响应格式
                }).then((res) => {

                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
                    });
                    aLink.href = URL.createObjectURL(blob)
                    aLink.download = file.fileName //标题
                    aLink.click()
                    document.body.appendChild(aLink)
                })
            },
        }
    }
</script>

<style lang='css' scoped>
    @import '../../../index.css';
</style>
